﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.IO;

using LuaInterface;

namespace CodeGame.LuaLibary
{
    static class luaLib_file
    {
        [LuaHelp("Reads all text from a text file")]
        public static string read(string filename)
        {
            return File.ReadAllText(filename);
        }

        [LuaHelp("Writes the speciyed text to a text file")]
        public static void write(string filename, string data)
        {
            File.WriteAllText(filename, data);
        }

        [LuaHelp("Gets all lua files stored in a directory")]
        public static List<string> getLuaFiles(string dir)
        {
            string[] files = Directory.GetFiles(dir, "*.lua");
            List<string> items = new List<string>();

            foreach (string item in files)
            {
                items.Add(item);
            }

            return items;
        }

        [LuaHelp("Reloads the bacic lua libary stored in the \"lib\" dir")]
        public static void reloadLib()
        {
            Singletons.Scripting.LoadLuaSideLibary(false);
        }
    }
}
